package knowall.client.questionCreation;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Label;

public class QuestionCreationInterface extends Composite {

	private static QuestionCreationInterfaceUiBinder uiBinder = GWT.create(QuestionCreationInterfaceUiBinder.class);

	interface QuestionCreationInterfaceUiBinder extends UiBinder<Widget, QuestionCreationInterface> {
		
	}

	public QuestionCreationInterface() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField Button button;
	@UiField Label questionTextLabel;
	@UiField Label questionTextLbl;
	List<String> words = new ArrayList<String>();

	public QuestionCreationInterface(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));
		button.setText(firstName);
	}

	@UiHandler("button")
	void onClick(ClickEvent e) {
		button.setEnabled(false);
		// Create the new popup.
        final QuestionTextPopup popup = new QuestionTextPopup(button, words);
        // Position the popup 1/3rd of the way down and across the screen, and
        // show the popup. Since the position calculation is based on the
        // offsetWidth and offsetHeight of the popup, you have to use the
        // setPopupPositionAndShow(callback) method. The alternative would
        // be to call show(), calculate the left and top positions, and
        // call setPopupPosition(left, top). This would have the ugly side
        // effect of the popup jumping from its original position to its
        // new position.
        popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
          public void setPosition(int offsetWidth, int offsetHeight) {
            int left = (Window.getClientWidth() - offsetWidth) / 3;
            int top = (Window.getClientHeight() - offsetHeight) / 3;
            popup.setPopupPosition(left, top);
          }
        });
	}

	public void setText(String text) {
		button.setText(text);
	}

	public String getText() {
		return button.getText();
	}
	
}
